/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 **************************************************************************
 * MIFSS  - content storage system
 * 
 *
 * @uthors: uros.kristan@gmail.com (Uroš Kristan ) Urosk.NET
 *         jernej.svigelj@gmail.com (Jernej Švigelj) 
 */
package net.monare.mifss.configurations.pojo;

import org.codehaus.jackson.annotate.JsonIgnore;

import org.eclipse.persistence.annotations.HashPartitioning;
import org.eclipse.persistence.annotations.Partitioned;

import javax.persistence.*;
import java.util.Date;

// TODO: use @ValuePartitioning and @Partitioned annotations for partitions

@Entity
@Table(name="mifss_content_meta_data")
public class ContentMetaDataDef {

    @EmbeddedId
    private ContentMetaDataKey contentMetaDataKey;

    private Long dataSize;
    private String extension;
    private String fileHash;
    private String fileHashMethod;
    private String fileName;
    private Long idContent;
    private int idContentPool;
    private Long idUser;

    @Temporal(TemporalType.TIMESTAMP)
    private Date inserted;

    @Lob
    private String metaData;
    private String mimeType;
    private String originalFilePath;
    private String title;

    private int transformation;

    /**
     * Returns 1 if file was transformed from its original - rendition Returns 0
     * if this is untransformed file
     *
     * @return
     */
    @JsonIgnore
    public boolean isTransformation() {
        return transformation > 0;
    }

    public int getTransformation() {
        return transformation;
    }

    public void setTransformation(int transformation) {
        this.transformation = transformation;
    }

    public Long getDataSize() {
        return dataSize;
    }

    public String getExtension() {
        return extension;
    }

    public String getFileHash() {
        return fileHash;
    }

    public String getFileHashMethod() {
        return fileHashMethod;
    }

    public String getFileName() {
        return fileName;
    }

    public Long getIdContent() {
        return idContent;
    }

    public int getIdContentPool() {
        return idContentPool;
    }

    public Long getIdUser() {
        return idUser;
    }

    public Date getInserted() {
        return inserted;
    }

    public String getMetaData() {
        return metaData;
    }

    public String getMimeType() {
        return mimeType;
    }

    public String getOriginalFilePath() {
        return originalFilePath;
    }

    public String getTitle() {
        return title;
    }

    public void setDataSize(Long dataSize) {
        this.dataSize = dataSize;
    }

    public void setExtension(String extension) {
        this.extension = extension;
    }

    public void setFileHash(String fileHash) {
        this.fileHash = fileHash;
    }

    public void setFileHashMethod(String fileHashMethod) {
        this.fileHashMethod = fileHashMethod;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public void setIdContent(Long idContent) {
        this.idContent = idContent;
    }

    public void setIdContentPool(int idContentPool) {
        this.idContentPool = idContentPool;
    }

    public void setIdUser(Long idUser) {
        this.idUser = idUser;
    }

    public void setInserted(Date inserted) {
        this.inserted = inserted;
    }

    public void setMetaData(String metaData) {
        this.metaData = metaData;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public void setOriginalFilePath(String originalFilePath) {
        this.originalFilePath = originalFilePath;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        return "ContentMetaDataDef{" +
                "dataSize=" + dataSize +
                ", extension='" + extension + '\'' +
                ", fileHash='" + fileHash + '\'' +
                ", fileHashMethod='" + fileHashMethod + '\'' +
                ", fileName='" + fileName + '\'' +
                ", idContent=" + idContent +
                ", idContentPool=" + idContentPool +
                ", storageName='" +  getStorageName() + '\'' +
                ", idUser=" + idUser +
                ", inserted=" + inserted +
                ", metaData='" + metaData + '\'' +
                ", mimeType='" + mimeType + '\'' +
                ", originalFilePath='" + originalFilePath + '\'' +
                ", title='" + title + '\'' +
                ", uuid='" + getUuid() + '\'' +
                ", transformation=" + transformation +
                '}';
    }

    public String getStorageName() {
        if(contentMetaDataKey != null) {
            return contentMetaDataKey.getStorageName();
        } else {
            return null;
        }
    }

    public void setStorageName(String storageName) {
        if (contentMetaDataKey == null){
            contentMetaDataKey = new ContentMetaDataKey();
        }

        this.contentMetaDataKey.setStorageName(storageName);
    }

    public ContentMetaDataKey getContentMetaDataKey() {
        return contentMetaDataKey;
    }

    public void setContentMetaDataKey(ContentMetaDataKey contentMetaDataKey) {
        this.contentMetaDataKey = contentMetaDataKey;
    }

    public void setUuid(String uuid) {
        if (contentMetaDataKey == null){
            contentMetaDataKey = new ContentMetaDataKey();
        }
        this.contentMetaDataKey.setUuid(uuid);
    }

    public String getUuid() {
        if(contentMetaDataKey != null) {
            return contentMetaDataKey.getUuid();
        } else {
            return null;
        }
    }

}